﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Vit.Web.Services;

namespace Vit.Web.Extensions
{
    public static class ControllerExtension
    {
        public static string Localize(this Controller controller, string resourceName, params object[] values)
        {
            string areaName = controller.RouteData.DataTokens["area"] as string ?? "";
            IUnityContainer unity = ((VitApplication)HttpContext.Current.ApplicationInstance).UnityContainer;
            ILocalizationService localize = unity.Resolve<ILocalizationService>();
            return localize.Resource(areaName, resourceName, values);
        }

        public static string[] GetEntityIds(string ids)
        {
            if (ids.IndexOf("_") <= 0)
                return new string[] { ids };

            return ids.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
        }
    }
}
